using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.JsonConverters
{
    public class LocationAdditionConverter : JsonConverter<ILocationAddition>
    {
        public override ILocationAddition Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            throw new NotImplementedException();
        }

        public override void Write(Utf8JsonWriter writer, ILocationAddition value, JsonSerializerOptions options)
        {
            var parser = JT808MsgBodyParserFactory.GetLocationAddtionParser(value.AdditionID);
            switch (value)
            {
                case null:
                    JsonSerializer.Serialize(writer, value, options);
                    break;

                default:
                    var type = parser.GetType();
                    JsonSerializer.Serialize(writer, value, type, options);
                    break;
            }
        }
    }
}